import 'package:flutter/material.dart';
import 'package:xindong/common/xindong_sezhi.dart';
import 'package:xindong/common/xindong_methods.dart';
import 'package:xindong/manager/xindong_gift_animation_ctr.dart';
import 'package:xindong/models/gift/xindong_gift_class.dart';
import 'package:xindong/res/assets_res.dart';
import 'package:xindong/utils/xindong_image_util.dart';
import 'package:xindong/utils/xindong_text_util.dart';
import 'package:xindong/utils/queue/xindong_svga_queue.dart';
import 'package:xindong/widgets/gift/xindong_songli_controller.dart';
import 'package:xindong/widgets/xindong_count_red_dots.dart';

// 礼物Item
class XinDongSongLiGridViewItem extends StatelessWidget {
  final XinDongGiftClass model;
  final bool selected;
  final Function(XinDongGiftClass) onSelected;

  const XinDongSongLiGridViewItem({Key? key, required this.model, this.selected = false, required this.onSelected})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () => onSelected(model),
      onLongPress: () {
        if (TextUtil.isEmpty(model.cover)) {
          showToast("礼物无特效");
          return;
        }
        XinDongGiftAnimationCtr.to.addQueue(SVGAClass(
          type: SVGAType.receiveGift,
          name: model.name,
          svga: model.cover ?? "",
        ));
      },
      behavior: HitTestBehavior.opaque,
      child: Container(
        margin: const EdgeInsets.only(left: 5, right: 5),
        decoration: BoxDecoration(
          border: Border.all(color: selected ? DZColors.mainLightColor : Colors.transparent, width: 1),
          borderRadius: BorderRadius.circular(8.0),
        ),
        child: Stack(
          alignment: Alignment.center,
          children: [
            Column(
              mainAxisSize: MainAxisSize.min,
              children: [
                // 图标
                Stack(
                  alignment: Alignment.center,
                  children: [
                    ImageUtil.networkImageUrl(model.preview, width: 72, height: 72, placeholder: const SizedBox()),
                    model.cate_id == XinDongLiWuType.backpack
                        ? Positioned(
                            top: 2,
                            right: 0,
                            child: XinDongUnreadCountWidget(count: model.total, height: 15, fontSize: 9),
                          )
                        : const SizedBox(),
                  ],
                ),

                // 名称
                Text(
                  model.name,
                  maxLines: 1,
                  overflow: TextOverflow.ellipsis,
                  style: const TextStyle(fontSize: 13, color: DZColors.titleColor),
                ),

                const SizedBox(height: 3),

                // 礼物价值
                Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    Text(
                      model.price,
                      style: const TextStyle(fontSize: 12, color: DZColors.placeholderColor, height: 1.2),
                    ),
                    const SizedBox(width: 2),
                    SizedBox(
                      width: 12,
                      height: 12,
                      child: ImageUtil.asset(AssetsRes.ICON_GOLD_COIN),
                    ),
                  ],
                ),
                const SizedBox(height: 8),
              ],
            ),

            // 标签
            // buildContainerMark(model.tag),
          ],
        ),
      ),
    );
  }

  /// 标签
//
// buildContainerMark(XinDongGiftTag? tag) {
//   if (model.tag == null || TextUtil.isEmpty(model.tag?.name)) {
//     return SizedBox();
//   }
//   return Positioned(
//     top: 0,
//     right: 0,
//     child: Container(
//       height: 16,
//       padding: EdgeInsets.only(left: 6, right: 6),
//       decoration: BoxDecoration(
//         borderRadius: BorderRadius.only(bottomLeft: Radius.circular(8), topRight: Radius.circular(8)),
//         gradient: LinearGradient(
//           begin: Alignment.topRight,
//           end: Alignment.bottomLeft,
//           colors: [
//             DZColors.hexStringColor("${model.tag?.tagColor}"),
//             DZColors.hexStringColor("${model.tag?.bgColor}"),
//           ],
//         ),
//       ),
//       child: Row(
//         mainAxisSize: MainAxisSize.min,
//         children: [
//           Text(
//             "${model.tag?.name}",
//             textAlign: TextAlign.center,
//             style: TextStyle(fontSize: 10, fontWeight: FontWeight.normal, color: Colors.white),
//           ),
//         ],
//       ),
//     ),
//   );
// }
}
